﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Boxie
{
    public partial class frmMusicTag : Form
    {
        public frmMusicTag()
        {
            InitializeComponent();
            if (BoxieRegLib.GetSettingBool("General/WindowTopMost", true))
                this.TopMost = true;
        }

        public void PopulateList()
        {
            lstFiles.Items.Clear();
            for (int x = 0; x < frmBoxie.instance.appargs.Length; x++)
            {
                ListViewItem lvi = lstFiles.Items.Add(System.IO.Path.GetFileName(frmBoxie.instance.appargs[x]));
                lvi.ToolTipText = frmBoxie.instance.appargs[x];
            }
        }

        private void lstFiles_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                txtMusicInfo.Text = "Loading...";
                txtMusicInfo.Refresh();
                txtMusicInfo.Text = Boxie.BoxieMusicLib.ReadTagData(lstFiles.SelectedItems[0].ToolTipText);
            }
            catch (Exception ee)
            {
                // Om nom nom.
            }
        }

        private void btnProcessFiles_Click(object sender, EventArgs e)
        {
            int c = lstFiles.Items.Count - 1;
            String[] fnOld = new String[c+1];
            btnProcessFiles.Text = "Processing...";
            btnProcessFiles.Enabled = false;
            btnProcessFiles.Refresh();
            for (int x = 0; x <= c; x++)
                fnOld[x] = lstFiles.Items[x].ToolTipText;
            bool success = Boxie.BoxieMusicLib.DoTagging(fnOld, txtMusicFormat.Text);
            if(success)
            {
                lstFiles.Items.Clear();
                txtMusicInfo.Text = "";
                Boxie.frmBoxie.instance.ClearEntireQueue();
                this.Visible = false;
            }
            btnProcessFiles.Text = "Process Files";
            btnProcessFiles.Enabled = true;
        }
    }
}
